<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-body">
              <div class="layui-form" lay-filter="">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline" style="width: 380px;">
                      <input
                        type="text"
                        name="name"
                        placeholder="用户名"
                        v-model="itemData.name"
                        autocomplete="off"
                        class="layui-input"
                        disabled="ture"
                      />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline" style="width: 380px;">
                      <input
                        type="password"
                        name="password"
                        placeholder="密码"
                        v-model="itemData.password"
                        autocomplete="off"
                        class="layui-input"
                      />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-inline" style="width: 380px;">
                      <input
                        type="text"
                        name="nickName"
                        placeholder="昵称(限10字)"
                        v-model="itemData.nickName"
                        autocomplete="off"
                        class="layui-input"
                        maxlength="10"
                      />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">email</label>
                  <div class="layui-input-inline" style="width: 380px;">
                    <input
                      type="text"
                      name="email"
                      placeholder="邮箱"
                      v-model="itemData.email"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">手机</label>
                  <div class="layui-input-inline" style="width: 380px;">
                    <input
                      type="text"
                      name="mobile"
                      placeholder="手机(11位数)"
                      v-model="itemData.mobile"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">手机状态</label>
                  <div class="layui-input-inline" style="width: 380px;">
                    <select
                      name="mobileStatus"
                      lay-filter="mobileStatus"
                      v-model="itemData.mobileStatus"
                    >
                      <option value="UNCERTIFIED">待认证</option>
                      <option value="CERTIFIED_PASS">认证通过</option>
                      <option value="CERTIFIED_FAIL">认证不通过</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">激活状态 </label>
                  <div class="layui-input-inline" style="width: 380px;">
                    <select
                      name="activeStatus"
                      lay-filter="activeStatus"
                      v-model="itemData.activeStatus"
                    >
                      <option value="ENABLE">启用</option>
                      <option value="DISABLE">禁用</option>
                      <option value="DELETE">删除</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button
                      class="layui-btn layui-btn-normal"
                      lay-submit
                      @click="sure"
                    >
                      确认
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "useradd",
  data() {
    return {
      id: "",
      itemData: {
        name: "", //用户名
        password: "", //密码
        nickName: "", //昵称
        email: "", //邮箱
        mobile: "", //手机
        mobileStatus: "", //手机认证
        activeStatus: "", //激活状态
      },
    };
  },
  mounted() {
    var vm = this;
    window.getdates = this.getdates;
  },
  methods: {
    getdates: function (data) {
      var vm = this;
      this.id = data.id;
      var url = "/account/bapi/v1.9/users/" + data.id;
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        vm.itemData = ret.data;
      });
    },
    sure: function () {
      var vm = this;
      for (var i = 0; i < $(".a").length; i++) {
        if ($(".a").eq(i).val() == "" || $(".a").eq(i).val() <= 0) {
          var msg = $(".a").eq(i).attr("placeholder");
          layer.msg("请输入正确的" + msg);
          return;
        }
      }
      var tid = "POST";
      var dates = this.itemData;
      if (this.id) {
        dates.id = this.id;
        tid = "PUT";
      }
      var url = "/account/bapi/v1.9/users/";
      ajaxRequest(url, tid, "json", dates, function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
          parent.location.reload();
        }, 1000);
      });
    },
  },
  updated: function () {
    var vm = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
      form.on("select(mobileStatus)", function (data) {
        vm.itemData.mobileStatus = data.value;
        //	var name=data.elem.getAttribute('name');
      });
      form.on("select(activeStatus)", function (data) {
        vm.itemData.activeStatus = data.value;
        //	var name=data.elem.getAttribute('name');
      });
    });
  },
};
</script>
<style scoped></style>
